home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 79 / maccd 79.iso / multimedial / GL Tron / Source / gltron / input.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-05-26  |  4.8 KB  |  165 lines  |  [TEXT/CWIE]

  1. #define KEYBOARD
  2. #include "gltron.h"
  3.  
  4. /* I hear people are reading this file because they couldn't find the
  5.    manual! Go to http://www.ards.net/Andreas/gltron.html#usage         */
  6.  
  7. /* default actions */
  8.  
  9. keyAction key_actions[KEY_ACTIONS_N] = {
  10.   { 0, TURN_LEFT, 'a' },
  11.   { 0, TURN_RIGHT, 's' },
  12.   { 1, TURN_LEFT, 'k' },
  13.   { 1, TURN_RIGHT, 'l' },
  14.   { 2, TURN_LEFT, '5' },
  15.   { 2, TURN_RIGHT, '6' },
  16.   { 3, TURN_LEFT, SYSTEM_KEY_LEFT },
  17.   { 3, TURN_RIGHT, SYSTEM_KEY_RIGHT }
  18. };
  19.  
  20. #define KEY_RESERVED_N 8
  21. int reserved_keys[] = {
  22.   'q', 27, ' ',
  23.   SYSTEM_KEY_F1,
  24.   SYSTEM_KEY_F2,
  25.   SYSTEM_KEY_F3,
  26.   SYSTEM_KEY_F4,
  27.   SYSTEM_KEY_F5,
  28.   SYSTEM_KEY_F10,
  29.   SYSTEM_KEY_F11,
  30.   SYSTEM_KEY_F12,
  31.   SYSTEM_KEY_UP,
  32.   SYSTEM_KEY_DOWN
  33. };
  34.  
  35. void keyGame(int k, int x, int y)
  36. {
  37.   int i;
  38.  
  39.   switch (k) {
  40.   case 'q': SystemExit(); break; /* panic button */
  41.   case 27:
  42.     switchCallbacks(&pauseCallbacks);
  43.     switchCallbacks(&guiCallbacks);
  44.     break;
  45.   case ' ': switchCallbacks(&pauseCallbacks); break;
  46.  
  47.   case SYSTEM_KEY_F1: defaultDisplay(0); break;
  48.   case SYSTEM_KEY_F2: defaultDisplay(1); break;
  49.   case SYSTEM_KEY_F3: defaultDisplay(2); break;
  50.   case SYSTEM_KEY_F4: defaultDisplay(3); break;
  51.  
  52.   case SYSTEM_KEY_F10:
  53.     game->settings->camType = (game->settings->camType + 1) % CAM_COUNT;
  54.     for(i = 0; i < game->players; i++)
  55.       game->player[i].camera->camType = game->settings->camType;
  56.     break;
  57.  
  58.   case SYSTEM_KEY_F5: saveSettings(); break;
  59.   case SYSTEM_KEY_F11: doBmpScreenShot(); break;
  60.   case SYSTEM_KEY_F12: doScreenShot(); break;
  61.  
  62.   case SYSTEM_KEY_UP: consoleScrollBackward(1); break;
  63.   case SYSTEM_KEY_DOWN: consoleScrollForward(1); break;
  64.   case SYSTEM_KEY_F6: 
  65.       game->settings->light_cycles = !game->settings->light_cycles;
  66.       break;
  67.  
  68.   default: 
  69.     for(i = 0; i < KEY_ACTIONS_N; i++) {
  70.       if(k == key_actions[i].key) {
  71.     int p;
  72.     p = key_actions[i].player;
  73.     if(game->player[p].data->speed > 0)
  74.       createTurnEvent(p, key_actions[i].turn);
  75.     return;
  76.       }
  77.     }
  78.  
  79.     sprintf(messages, "key '%s' is not bound", SystemGetKeyName(k));
  80.     consoleAddLine(messages);
  81.     fprintf(stderr, "%s\n", messages);
  82.   }
  83. }
  84.  
  85. void parse_args(int argc, char *argv[]) {
  86.   int i;
  87.   while(argc--) {
  88.     if(argv[argc][0] == '-') {
  89.       i = 0;
  90.       while(argv[argc][++i] != 0) {
  91.     switch(argv[argc][i]) {
  92.     case 'k': game->settings->erase_crashed = 1; break;
  93.     case 'f': game->settings->fast_finish = 1; break;
  94.     case 'b': game->settings->show_alpha = 0; break;
  95.     case 'm': game->settings->show_model = 0; break;
  96.     case 'x': game->settings->show_crash_texture = 0; break;
  97.     case 'F': game->settings->show_fps = 0; break;
  98.     case 't': game->settings->show_floor_texture = 0; break;
  99.     case 'c': game->settings->show_ai_status = 0; break;
  100.     case 'g': game->settings->show_glow = 0; break;
  101.     case 'w': game->settings->show_wall = 0; break;
  102.     case 'C': game->settings->show_ai_status = 1; break;
  103.     case 'v': game->settings->screenSaver = 1; break;
  104.     case 'i': game->settings->windowMode = 1; break;
  105.     case 'M': game->settings->mouse_warp = 1; break;
  106.     case 'O': game->settings->softwareRendering = 1; break;
  107.     case '1': /* default is -2 */
  108.       game->settings->width = 320;
  109.       game->settings->height = 240;
  110.       break;
  111.     case '2': 
  112.       game->settings->width = 640;
  113.       game->settings->height = 480;
  114.       break;
  115.     case '3': 
  116.       game->settings->width = 800;
  117.       game->settings->height = 600;
  118.       break;
  119.     case '4': 
  120.       game->settings->width = 1024;
  121.       game->settings->height = 768;
  122.       break;
  123.     case '5': 
  124.       game->settings->width = 1280;
  125.       game->settings->height = 1024;
  126.       break;
  127.     case 's':
  128.       game->settings->playMusic = 0;
  129.       game->settings->playEffects = 0;
  130.       break;
  131.     case 'h':
  132.     default:
  133.       printf("Usage: %s [-FftwbghcCsk1234simo]\n\n", argv[0]);
  134.       printf("Options:\n\n");
  135.       printf("-k\terase crashed players (like in the movie)\n");
  136.       printf("-f\tfast finish after human has crashed\n");
  137.       printf("-F\tdon't display FPS counter\n");
  138.       printf("-t\tdon't display floor texture, use lines instead"
  139.          "(huge speed gain)\n");
  140.       printf("-w\tdon't display walls (speed gain)\n");
  141.       printf("-b\tdon't use blending (speed gain)\n");
  142.       printf("-m\tdon't show lightcycle (speed gain)\n");
  143.       printf("-x\tdon't show crash texture (speed gain)\n");
  144.       printf("-g\tdon't show glows (small speed gain)\n");
  145.       printf("-c\tdon't show ai status\n");
  146.       printf("-C\tshow ai status (default: on)\n");
  147.       printf("-1\tSet resolution to 320x240\n");
  148.       printf("-2\tSet resolution to 640x480 (default)\n");
  149.       printf("-3\tSet resolution to 800x600\n");
  150.       printf("-4\tSet resolution to 1024x768\n");
  151.       printf("-5\tSet resolution to 1280x1024\n");
  152.       printf("-s\tDon't play sound\n");
  153.       /* printf("-v\tStart in demo/screensaver mode\n"); */
  154.       printf("-i\tforce startup in a window\n");
  155.       printf("-M\tcapture mouse (useful for Voodoo1/2 owners)\n");
  156.       printf("-O\toptimize for software rendering (SLOWER on "
  157.          "3D cards!)\n");
  158.       printf("-h\tthis help\n");
  159.       exit(1);
  160.     }
  161.       }
  162.     }
  163.   }
  164. }
  165.